package homework;
//作业标题(2720)
//最小栈
//
//作业内容
//最小栈
//https://leetcode.cn/problems/min-stack/

import java.util.Stack;

public class h2720{
    class MinStack {
    Stack<Integer> stack;
    Stack<Integer> minStack;

    public MinStack() {
        stack = new Stack<>();
        minStack = new Stack<>();
    }

    public void push(int val) {
        stack.push(val);
        if(minStack.empty() || minStack.peek() > val) {
            minStack.push(val);
        }else {
            minStack.push(minStack.peek());
        }
    }

    public void pop() {
        stack.pop();
        minStack.pop();
    }

    public int top() {
        return stack.peek();
    }

    public int getMin() {
        return minStack.peek();
    }
}
}
